package net.alche.al.util;

import net.alche.al.util.far.FaBaseTheme;
import net.alche.al.util.far.FaBaseTidy;
import net.alche.al.util.far.FaBaseLogic;

import java.util.Date;

import javax.swing.Renderer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import net.alche.al.util.far.FaBaseAc;
import net.alche.al.util.far.FaBaseHttp;
import net.alche.al.util.far.FaBaseStore;
import net.alche.al.util.far.FaBasePlugin;
import net.alche.al.util.far.FaBaseSage;
import net.alche.al.util.far.FaBaseTol;
import net.alche.al.util.far.FaBaseUi;
import net.alche.al.util.far.plugin.gson.GsonDateAdapter;
import net.alche.al.util.far.plugin.gson.GsonDoubleAdapter;
import net.alche.al.util.far.plugin.gson.GsonIntegerAdapter;
import net.alche.al.util.far.plugin.gson.GsonLongAdapter;
import net.alche.al.util.far.FaBaseJava;
// import org.apache.logging.log4j.LogManager;
// import org.apache.logging.log4j.Logger;

// Far
// @JsonIgnoreProperties(value = { "handler", "hibernateLazyInitializer", "fieldHandler" })
public class Far {
  public static Gson gson = instanceGson();
  // public static SimpleDateFormat formatDateTime= new
  // SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  // public static SimpleDateFormat formatDate= new
  // SimpleDateFormat("yyyy-MM-dd");
  public static FaBaseTheme theme = new FaBaseTheme();
  public static FaBaseLogic lc = new FaBaseLogic();
  public static FaBaseHttp http = new FaBaseHttp();
  public static FaBaseStore store = new FaBaseStore();
  public static FaBasePlugin plugin = new FaBasePlugin();
  public static FaBaseTol tl = new FaBaseTol();
  public static FaBaseUi ui = new FaBaseUi();
  public static FaBaseJava java = new FaBaseJava();
  public static FaBaseSage sageUtil = new FaBaseSage();
  public static FaBaseAc ac = new FaBaseAc();
  public static FaBaseTidy tidy = new FaBaseTidy();
  public static final Logger logger = LoggerFactory.getLogger(Far.class);

  public static Gson instanceGson() {
    GsonBuilder bd = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss");
    bd.registerTypeAdapter(Integer.class, new GsonIntegerAdapter());
    bd.registerTypeAdapter(Long.class, new GsonLongAdapter());
    bd.registerTypeAdapter(Double.class, new GsonDoubleAdapter());
    bd.registerTypeAdapter(Date.class, new GsonDateAdapter());
    return bd.create();
  }

  public static void log(Object... param) {
    String log = null;
    for (Object ob : param) {
      log = (log == null ? "" : log + " , ")
          + (ob == null ? "null" : (ob instanceof String ? ob : Far.tl.toJsonTxt(ob)));
    }
    System.out.println(Far.tl.nowFmt("yyyy-MM-dd HH:mm:ss") + " [log] " + log);
  }

  public static void logDebug(Object... param) {
    String log = null;
    for (Object ob : param) {
      log = (log == null ? "" : log + " , ")
          + (ob == null ? "null" : (ob instanceof String ? ob : Far.tl.toJsonTxt(ob)));
    }
    logger.debug(log);
  }

  public static void logInfo(Object... param) {
    String log = null;
    for (Object ob : param) {
      log = (log == null ? "" : log + " , ")
          + (ob == null ? "null" : (ob instanceof String ? ob : Far.tl.toJsonTxt(ob)));
    }
    logger.info(log);
  }

  public static void logError(Object... param) {
    String log = null;
    for (Object ob : param) {
      log = (log == null ? "" : log + " , ")
          + (ob == null ? "null" : (ob instanceof String ? ob : Far.tl.toJsonTxt(ob)));
    }
    logger.error(log);
  }
}
